Skip to content

Solve memoverride.cpp failing to override all versions of new/new[]/delete/delete[] - #4

Open
RaphaelIT7 wants to merge 2 commits into
misyltoad:masterfrom
RaphaelIT7:patch-2
Open

Solve memoverride.cpp failing to override all versions of new/new[]/delete/delete[]#4
RaphaelIT7 wants to merge 2 commits into
misyltoad:masterfrom
RaphaelIT7:patch-2

Conversation

@RaphaelIT7

Copy link
Copy Markdown
Contributor

This is a fun one - Solves misyltoad/VPhysics-Jolt#259

Example of this issue:
JPH::Ref<JPH::CharacterSettings> settings = new JPH::CharacterSettings();
in this line it internally allocates the memory using g_pMemAlloc->Alloc since memoverride overwrote new
Now, when the JPH::Ref leaves the scope / gets released, it calls delete static_cast<const T *>(this);
The issue with that is, that in C++17 & higher there is __cpp_aligned_new which introduces more versions of new, new[], delete, delete[]
which are all not accounted for leaving them in a weird state where they might call the memoverride version - or they call the C++ standart version which ends up trying to delete the memory as aligned memory.
And for this example case it tries to call void operator delete( void* pMem, size_t sz, std::align_val_t align ) noexcept which was not overwritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant